package com.gxuwz.medical.web.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.policy.*;

public class PolicyServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
 
		this.doPost(request, response);
	 
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m = request.getParameter("m");
		if("list".equals(m)){
			process(request,response,"/page/policy/policy_list.jsp");
		}else if("get".equals(m)){
			process(request,response,"/page/policy/policy_edit.jsp");
		}else if("input".equals(m)){
			process(request,response,"/page/policy/policy_add.jsp");
		}else if("add".equals(m)){
			add(request,response);
			process(request,response,"/page/policy/policy_list.jsp");
		}else if("del".equals(m)){
			del(request,response);
			process(request,response,"/page/policy/policy_list.jsp");
		}else if("edit".equals(m)){
			edit(request,response);
			process(request,response,"/page/policy/policy_list.jsp");
		}
	}

	protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String pyear = request.getParameter("year");
		String plimit = request.getParameter("limit");
		Double plimit1 = Double.parseDouble(plimit);
		String rate = request.getParameter("rate");
		String status = request.getParameter("status");
		Policy policy = new Policy();
		policy.setPyear(pyear);
		policy.setPlimit(plimit1);
		policy.setRate(rate);
		policy.setStatus(status);
		
		try{
			policy.addPolicy();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	protected void del(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String pyear = request.getParameter("id");
		
		Policy policy = new Policy();
		
		try{
			policy.delPolicy(pyear);
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	
	protected void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String pyear = request.getParameter("year");
		String plimit = request.getParameter("limit");
		Double plimit1 = Double.parseDouble(plimit);
		String rate = request.getParameter("rate");
		String status = request.getParameter("status");
		Policy policy = new Policy();
		policy.setPyear(pyear);
		policy.setPlimit(plimit1);
		policy.setRate(rate);
		policy.setStatus(status);
		
		try{
			policy.editPolicy();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
